package util;

import net.sourceforge.pinyin4j.PinyinHelper;

public class PinYin {
	public static String getPinyin(String str) {
		StringBuilder s =new StringBuilder();
		for (int i = 0; i < str.length(); i++) {
			char c=str.charAt(i);
			String[] pinyinArray = PinyinHelper.toHanyuPinyinStringArray(c);
				if (null!=pinyinArray){
					s.append(pinyinArray[0]);
				}
				else{
					s.append(c);
				}
		}
		return s.toString();
	}

	public static String getPinyin2(String str) {
		// TODO Auto-generated method stub
		String tmp=str.replaceAll("[0-9]", "#");
		if(tmp.equals(""))
			return str;
		return tmp;
	}
	
	public static void main(String args[]){
		System.out.println(getPinyin2("sa23f4afaf1"));
		System.out.println(getPinyin2(""));
		System.out.println(getPinyin2(getPinyin("算法")));
		System.out.println("算法".length());
		System.out.println("算".length());
	}
	
}


